package com.ocgs.service.impl;

import com.ocgs.base.core.exception.BaseDAOException;
import com.ocgs.base.core.exception.BaseServiceException;
import com.ocgs.dao.impl.CustomerDAOImpl;
import com.ocgs.model.Customer;
import com.ocgs.pagination.PaginatedListImpl;
import com.ocgs.pagination.page.PageContext;
import com.ocgs.service.CustomerService;
import org.displaytag.pagination.PaginatedList;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: bryant
 * Date: 10/21/12
 * Time: 3:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class CustomerServiceImpl implements CustomerService {

    private CustomerDAOImpl customerDAO;

    public void setCustomerDAO(CustomerDAOImpl customerDAO) throws BaseServiceException {
        this.customerDAO = customerDAO;
    }

    public int deleteByPrimaryKey(Integer id) throws BaseServiceException {
       try{
           return customerDAO.deleteByPrimaryKey(id);
       }catch (BaseDAOException e){
           throw new BaseServiceException(e);
       }

    }

    public int insert(Customer record) throws BaseServiceException{
        try{
            return customerDAO.insert(record);
        }catch (BaseDAOException e){
            throw new BaseServiceException(e);
        }
    }
    public int insertSelective(Customer record) throws BaseServiceException {
        try{
            return customerDAO.insert(record);
        }catch (BaseDAOException e){
            throw new BaseServiceException(e);
        }
    }

    
    public Customer selectByPrimaryKey(Integer id) throws BaseServiceException {
        try{
            return customerDAO.selectByPrimaryKey(id);
        }catch (BaseDAOException e){
            throw new BaseServiceException(e);
        }
    }

    
    public int updateByPrimaryKeySelective(Customer record) throws BaseServiceException {
        try{
            return customerDAO.updateByPrimaryKeySelective(record);
        }catch (BaseDAOException e){
            throw new BaseServiceException(e);
        }
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(Customer record) throws BaseServiceException {
        return 0;  //To change body of implemented methods use File | Settings | File Templates.
    }


    public int updateByPrimaryKey(Customer record) throws BaseServiceException {
        try{
            return customerDAO.updateByPrimaryKey(record);
        }catch (BaseDAOException e){
            throw new BaseServiceException(e);
        }
    }

    public String retrieveCustomerAddress(Customer record) throws BaseServiceException {
        try{
            return customerDAO.retrieveCustomerAddress(record);
        }catch (BaseDAOException e){
            throw new BaseServiceException(e);
        }
    }


    public PaginatedList findAllCustomerForPagination(PaginatedListImpl paginatedList,Customer customer) throws BaseServiceException{

        try{
            PageContext page = PageContext.getPageContext();
            List<Customer> customers = customerDAO.findAllCustomer(customer);
            if(customers==null||customers.size()==0)
                return null;
            paginatedList.setList(customers);
            paginatedList.setTotalNumberOfRows(page.getTotalRows());
            return  paginatedList;
        }catch (BaseDAOException e){
            throw new BaseServiceException(e);
        }
    }

//    public List<customer> findAllCustomer() throws BaseServiceException {
//        try{
//           return customerDAO.findAllCustomer(new customer());
//        }catch (BaseDAOException e){
//            throw new BaseServiceException(e);
//        }
//    }
//
//    public List<customer> getAllCustomer() throws BaseServiceException{
//        try{
//            return customerDAO.getAllCustomer();
//        }catch (BaseDAOException e){
//            throw new BaseServiceException(e);
//        }
//    }
//
//    public PaginatedList findAllStorageForPagination(PaginatedListImpl paginatedList,customer customer) throws BaseServiceException{
//        try{
//            PageContext page = PageContext.getPageContext();
//            List<customer> customers = customerDAO.searchStorage(customer);
//            if(customers==null||customers.size()==0)
//                return null;
//            paginatedList.setList(customers);
//            paginatedList.setTotalNumberOfRows(page.getTotalRows());
//            return  paginatedList;
//        }catch (BaseDAOException e){
//            throw new BaseServiceException(e);
//        }
//    }
}
